package com.wecloud.core.data.jnlservice;

import java.util.Date;
import java.util.Map;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;

import com.wecloud.core.constant.WeContext;
import com.wecloud.core.data.jnl.JnlService;
import com.wecloud.core.exception.WeException;
import com.wecloud.core.utils.DateUtils;
import com.wecloud.core.utils.GenarateSeqUtil;

public class RegisterJnlService extends JnlService{
	
	private String saveUser;
	

	public String getSaveUser() {
		return saveUser;
	}
	public void setSaveUser(String saveUser) {
		this.saveUser = saveUser;
	}
	@Override
	public void write(Map map) throws WeException {
		//保存
		getTransactionTemplate().execute(new TransactionCallback() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				try{
					String userid = GenarateSeqUtil.genarateID();
					map.put("userid", userid);
					map.put("role", "0");
					map.put("userStatus", "0");
					map.put("registerTime", DateUtils.getDateStr("yyyy-MM-dd"));
					map.put("updateTime", new Date());
					insert(saveUser, map);
				}catch (Exception  e) {
					getAnnotationDrivenTransactionManager().rollback(status);
					throw new  WeException(e);
				}
				return null;
			}
		});
	}
}
